/*
 * @Author: szx
 * @Date: 2022-03-30 14:46:27
 * @LastEditTime: 2022-03-30 14:50:06
 * @Description:
 * @FilePath: \leetcode\100-199\198\198.js
 */
/**
 * @param {number[]} nums
 * @return {number}
 */
var rob = function (nums) {
    const n = nums.length;
    const dp = new Array(n + 1).fill(0);
    dp[1] = nums[0];
    for (let i = 2; i <= n; i++) {
        dp[i] = Math.max(dp[i - 2] + nums[i - 1], dp[i - 1]);
    }
    return dp[n];
};

var rob = function (nums) {
    const n = nums.length;
    let dp0 = 0;
    let dp1 = nums[0];
    let res = dp1;
    for (let i = 2; i <= n; i++) {
        res = Math.max(dp0 + nums[i - 1], dp1);
        dp0 = dp1;
        dp1 = res;
    }
    return res;
};
